import json


def format_info(value):
    """返回值json字符串格式化成字典"""
    if isinstance(value, dict):
        for k, v in value.items():
            if isinstance(v, str) and (v.startswith('{') or v.startswith("[")):
                try:
                    value[k] = json.loads(v)
                except Exception:
                    value[k] = v
            elif isinstance(v, list):
                for e in v:
                    if isinstance(e, dict):
                        for h, j in e.items():
                            if isinstance(j, str) and (j.startswith('{') or j.startswith("[")):
                                try:
                                    e[h] = json.loads(j)
                                except Exception:
                                    e[h] = j
                    elif isinstance(e, str) and (e.startswith('{') or e.startswith("[")):
                        try:
                            value[value.items(e)] = json.loads(e)
                        except Exception:
                            value[value.items(e)] = e
            elif isinstance(v, dict):
                for a, c in v.items():
                    if isinstance(c, str) and (c.startswith('{') or c.startswith("[")):
                        try:
                            v[a] = json.loads(c)
                        except Exception:
                            v[a] = c
            format_info(v)
    return value


def json_dumps(res):
    return json.dumps(res, indent=4, ensure_ascii=False)


def json_loads(res):
    return json.dumps(res, indent=4, ensure_ascii=False)


a = {"user": '{\"a\":1, \"passwd\":\"123456\"}'}
print(format_info(a)["user"]["passwd"])
print(type(format_info(a)))
